var jiedan
var index
var url
layui.use(['table','form','layer','jquery'], function() {
    var table = layui.table
    var form = layui.form
    var layer = layui.layer
    var $ = layui.jquery

    // 初始table
    jiedan = table.render({
        elem: "#jiedan"
        , url: "/deliverer/findOrder"
        , page: {limit: 5, limits: [5, 10, 15]}
        , cellMinWidth: 80
        , toolbar: '#tooljiedan'
        , cols: [[ //表头

            ,{type: 'checkbox', fixed: 'left'}
            , {field: 'orderId', title: '订单号', fixed: 'center',width: 200}
            , {field: 'userId', title: '用户ID', fixed: 'center',width: 200}
            , {field: 'money', title: '金额', fixed: 'center',width: 200}
            , {field: 'createTime', title: '创建时间', fixed: 'center',width: 200}
            , {field: 'state', title: '状态', fixed: 'center',width: 200 ,templet: function (data) {
                    return data.state == 1 ? "不可接单" : "可接单"
                }}

            , {fixed: 'right', title: '操作', toolbar: '#barjiedan', width: 300}
        ]]
    })
    // 查询
    form.on("submit(formDemo)", function (data) {
        delivererTable.reload({
            url: "/deliverer/findOrder"
            , where: {
                'orderId':data.field.orderId
                ,'userId':data.field.userId
                ,'money':data.field.money
                ,'createTime':data.field.createTime

            }
            , page: {
                curr: 1
            }
        })
        return false;
    })
    // 头部工具栏添加事件
    table.on('toolbar(jiedan)',function(obj) {
        if(obj.event=="jiedan"){
            jiedan(obj)
        }
    })
    //监听行工具事件
    table.on('tool(jiedan)', function(obj){
        var data = obj.data
        if(obj.event == "jiedan"){
            jiedan1(data)
        }
    })


    function jiedan1(data) {
        layer.confirm("您确定要接这个单么？", function (ind) {

            $.post("/deliverer/updateOrder", {"orderId": data.orderId}, function (d) {
                layer.msg(d.msg)
                // 刷新table数据
                jiedan.reload()

            })
            layer.close(ind)
        })
    }





 })